// app.js
App({
    onLaunch: function () {
        if (!wx.cloud) {
          console.error('请使用 2.2.3 或以上的基础库以使用云能力');
        } else {
          wx.cloud.init({
            env: 'cloud1-6gsv4k6hcacb77b6',
            traceUser: true,
          });
        }
        this.getweather()
        this.globalData = {};
    },
    //获取天气数据
    getweather:function(){
        var that = this
        wx.getLocation({
          type: 'wgs84',
          success (res) {
            console.log(res)
            const latitude = res.latitude//eb0c86513b134bd4a66b87e35b9f8f8a
            const longitude = res.longitude//75d2be769efa45e9b0aa62c0993fb5f2
            const key='eb0c86513b134bd4a66b87e35b9f8f8a'// 放上你自己的key
            wx.request({
              url: `https://nj6r6pwu2k.re.qweatherapi.com/geo/v2/city/lookup?location=${longitude},${latitude}&key=${key}`,
              success (res) {
                console.log('res',res.data)
                wx.setStorageSync('city', res.data.location[0])
                //获取天气
                wx.request({
                  url: `https://nj6r6pwu2k.re.qweatherapi.com/v7/weather/now?location=${longitude},${latitude}&key=${key}`,
                  success (res1) {
                    console.log('res1',res1.data)
                    wx.setStorageSync('weather', res1.data.now)
                 }
                 }),
                 //获取三天,这里只取出明天的
                 wx.request({
                  url: `https://nj6r6pwu2k.re.qweatherapi.com/v7/weather/7d?location=${longitude},${latitude}&key=${key}`,
                  success (res2) {
                    console.log('res2',res2);
                    wx.setStorageSync('after_days', res2.data.daily)
                 }
                 })
                 //生活指数
                 wx.request({
                   url: `https://nj6r6pwu2k.re.qweatherapi.com/v7/indices/1d?type=1,8,3,5&location=${longitude},${latitude}&key=${key}`,
                   success (res3) {
                       console.log('res3',res3);
                    wx.setStorageSync('indicate', res3.data.daily)
                   }
                 })
              }
            })
          }
        })
    }
  })